// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

const {ccclass, property} = cc._decorator;

@ccclass
export default class Score extends cc.Component {

    static i : Score = null;

    private value : number = 0;
    private label : cc.Label = null;

    // LIFE-CYCLE CALLBACKS:

    onLoad () {

        Score.i = this;

        this.label = this.node.getComponent(cc.Label);
        this.clearScore();
    }

    getScore() {

        return this.value;
    }

    clearScore() {

        this.value = 0;
        this.label.string = this.value + '';

        this.label.node.scale = 1;
    }

    addScore(n : number) {

        this.value += n;
        this.label.string = this.value + '';
    }
 }
